//
//  MeTopView.m
//  AILove
//
//  Created by 甘世清 on 2023/12/17.
//

#import "MeTopView.h"
#import "nameEditView.h"
@implementation MeTopView

- (void)SQ_UIViewForSelfView{
     self.backgroundColor = SQHexColor(@"#000000", 0.7);
    [self addSubview:self.avatarImage];
    _headerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _headerBtn.backgroundColor = UIColor.clearColor;
    [self addSubview:self.headerBtn];
    [self.headerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.avatarImage);
    }];
    [self addSubview:self.nameLabel];
    [self.avatarImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(80);
        make.left.equalTo(self).offset(24);
        make.top.equalTo(self).offset(TopHeight+12);
    }];
    UIImageView * xiangji =  [[UIImageView alloc]init];
    xiangji.image = SQGetImage(@"相机 1");
    xiangji.contentMode = UIViewContentModeScaleAspectFit;
    [self addSubview:xiangji];
    [xiangji mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.avatarImage.mas_right);
        make.bottom.equalTo(self.avatarImage.mas_bottom);
        make.size.mas_equalTo(28);
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(120);
        make.top.equalTo(self.avatarImage).offset(8);
    }];
    [self addSubview:self.setButton];
    [self.setButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(50);
        make.centerY.equalTo(self.nameLabel);
        make.left.equalTo(self.nameLabel.mas_right).offset(-10);
    }];
    WS(weakSelf);
    [self.setButton setTouchBlock:^(SQCustomButton * _Nonnull button) {
        [weakSelf SQ_setnameButton];
    }];
    
    [self addSubview:self.ZSLabel];
    [self.ZSLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(60);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(17);
        make.height.mas_equalTo(20);
        make.left.equalTo(self.nameLabel).offset(14);
    }];
    
    UIImageView * zsimage = [[UIImageView alloc]init];
    zsimage.image = SQGetImage(@"钻石");
    zsimage.contentMode = UIViewContentModeScaleAspectFit;
    [self addSubview:zsimage];
    [zsimage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(32, 28));
        make.centerY.equalTo(self.ZSLabel);
        make.left.equalTo(self.ZSLabel).offset(-20);
    }];
    self.zuanshiButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.zuanshiButton.backgroundColor = UIColor.clearColor;
    [self addSubview:self.zuanshiButton];
    [self.zuanshiButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.centerY.equalTo(self.ZSLabel);
            make.width.mas_equalTo(80);
            make.height.mas_equalTo(30);
    }];
    
    [self addSubview:self.vipImage];
    [self.vipImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.width.mas_equalTo(SCREEN_WIDETH-48);
        make.height.mas_equalTo(112);
        make.bottom.equalTo(self.mas_bottom).offset(-10);
    }];
    
    [self.vipImage addSubview:self.ktLabel];
    [self.ktLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.vipImage).offset(16);
        make.width.mas_equalTo(90);
        make.height.mas_equalTo(24);
    }];
    
    YYLabel * label3 = [[YYLabel alloc]initWithFrame:CGRectMake(16, 50, SCREEN_WIDETH-100, 24)];
    label3.textVerticalAlignment = YYTextVerticalAlignmentCenter;
    label3.textAlignment = NSTextAlignmentCenter;
    label3.numberOfLines = 0;
    [self.vipImage addSubview:label3];
    NSDictionary *attributes = @{NSFontAttributeName:FONT_BOLD(14) , NSForegroundColorAttributeName: SQColor(@"#FFFFFF")};
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:SQNSLocalString(@"开通VIP会员，享受全部功能特权") attributes:attributes];
   
    //设置高亮色和点击事件
    [text yy_setTextHighlightRange:[[text string] rangeOfString:SQNSLocalString(@"VIP会员")] color:SQColor(@"#F9DB91") backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
       
    }];
    label3.attributedText = text;
    UIView * topBgView = [[UIView alloc]init];
    topBgView.backgroundColor = SQHexColor(@"#000000", 0.86);
     
//    UIImageView * topBgImage = [[UIImageView alloc]init];
//    topBgImage.image = SQGetImage(@"背景 2");
//    topBgImage.contentMode = UIViewContentModeScaleToFill;
    [self addSubview:topBgView];
    [topBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self);
        make.top.equalTo(self.vipImage).offset(90);
    }];
    
//    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemUltraThinMaterialDark];
//    UIVisualEffectView* visualView = [[UIVisualEffectView alloc]initWithEffect:effect];
//    visualView.frame =CGRectMake(0, 300, SCREEN_WIDETH, 30);
//    visualView.alpha = 0.99;
//    [self addSubview:visualView];
    
    [self addSubview:self.vipButton];
    [self.vipButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.vipImage);
    }];
  
    
}
-(void)SQ_model{
    UserModel * model = [UserModel share];
    [self.avatarImage sd_setImageWithURL:SQURLImage(model.portrait)];
    self.nameLabel.text = model.name;
    self.ZSLabel.text = [NSString stringWithFormat:@"%d",model.diamond];
    if (model.isVip) {
        self.vipImage.image = SQGetImage(@"背景 3");
        self.ktLabel.text = SQNSLocalString(@"VIP已开通");
    } else {
        self.vipImage.image = SQGetImage(@"背景");
        self.ktLabel.text = SQNSLocalString(@"VIP暂未开通");
    }
}


-(void)SQ_setnameButton{
    nameEditView * vc = [[nameEditView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDETH, SCREEN_HEIGHT)];
    LSTPopView * pop = [LSTPopView initWithCustomView:vc
                                           parentView:nil
                                             popStyle:LSTPopStyleFade dismissStyle:LSTDismissStyleFade];
    pop.hemStyle = LSTHemStyleCenter;
    pop.isAvoidKeyboard = NO;
    pop.adjustY = -70;
    [pop pop];
    LSTPopViewWK(pop)
    [vc.guanbi setTouchBlock:^(SQCustomButton * _Nonnull button) {
        [wk_pop dismiss];
    }];
    WS(weakSelf);
    [vc setDismissBlock:^{
        [wk_pop dismiss];
        [weakSelf SQ_model];
    }];
}


- (UIImageView *)avatarImage{
    if (!_avatarImage) {
        _avatarImage = [[UIImageView alloc]init];
        _avatarImage.contentMode = UIViewContentModeScaleAspectFill;
        _avatarImage.clipsToBounds = YES;
        _avatarImage.layer.cornerRadius = 40;
        _avatarImage.layer.borderColor = UIColor.whiteColor.CGColor;
        _avatarImage.layer.borderWidth = 1;
        _avatarImage.image = SQGetImage(@"头像 1");
    }
    return _avatarImage;
}
- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = FONT_BOLD(20);
        _nameLabel.text = SQNSLocalString(@"点击设置昵称");
        _nameLabel.textColor = UIColor.whiteColor;
    }
    return _nameLabel;
}

- (SQCustomButton *)setButton{
    if (!_setButton) {
        _setButton = [[SQCustomButton alloc]initType:SQCustomButtonTopImageType imageSize:CGSizeMake(20, 20) midmargin:0];
        _setButton.image = SQGetImage(@"编辑");
    }
    return _setButton;
}
- (UILabel *)ZSLabel{
    if (!_ZSLabel) {
        _ZSLabel = [[UILabel alloc]init];
        _ZSLabel.font = FONT_REGULAR(14);
        _ZSLabel.textColor = UIColor.whiteColor;
        _ZSLabel.textAlignment = NSTextAlignmentCenter;
        _ZSLabel.backgroundColor = SQHexColor(@"#FFFFFF", 0.24);
        _ZSLabel.text = @"0";
        _ZSLabel.layer.cornerRadius = 4;
        _ZSLabel.layer.masksToBounds = YES;
    }
    return _ZSLabel;
}
- (UIImageView *)vipImage{
    if (!_vipImage) {
        _vipImage = [[UIImageView alloc]init];
        _vipImage.layer.cornerRadius = 10;
        _vipImage.layer.masksToBounds = YES;
        _vipImage.backgroundColor = SQHexColor(@"#ffffff", 0.2);
    }
    return _vipImage;
}
- (UIButton *)vipButton{
    if (!_vipButton) {
        _vipButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _vipButton.backgroundColor = UIColor.clearColor;
    }
    return _vipButton;
}
- (UILabel *)ktLabel{
    if (!_ktLabel) {
        _ktLabel = [[UILabel alloc]init];
        _ktLabel.backgroundColor = SQHexColor(@"#000000", 0.16);
        _ktLabel.layer.cornerRadius = 12;
        _ktLabel.layer.masksToBounds = YES;
        _ktLabel.textAlignment = NSTextAlignmentCenter;
        _ktLabel.textColor = UIColor.whiteColor;
        _ktLabel.font = FONT_BOLD(12);
    }
    return _ktLabel;
}
@end
